<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%
    // 设置昵称
    List<User> users = QBuilder.db("basedb").queryHql("from User where id = " + token.getUid());
    if (users.size() == 0) {
         Tools.encryptPrint(out, new Message(30041, "用户不存在"));
         return;
    }
    User user = users.get(0);
	String nickName = filterIllegalCharacter(input.getDesc("nick_name", ""));
	if (nickName.contains(" ")) {
		// Tools.encryptPrint(out, new Message(30022, "昵称不能包含空格"));
        // return;
	}
	if (nickName.length() < 1 || nickName.length() > 10) {
		Tools.encryptPrint(out, new Message(30107, "昵称长度1-10位"));
        return;
	}
    user.setNickName(nickName);
    DBTools.db("basedb").modItem(user, user.getId());
    users = QBuilder.db("basedb").queryHql("from User where id = " + token.getUid());
    if (users.size() == 0) {
         Tools.encryptPrint(out, new Message(30041, "用户不存在"));
         return;
    }
    nickName = users.get(0).getNickName();
    if (!input.getDesc("nick_name", "").equals(nickName)) {
        Tools.encryptPrint(out, new Message(300108, "修改失败"));
        return;
    }
    msg.put("data", nickName);
    Tools.encryptPrint(out, msg);
%>
